﻿<UserControl x:Class="DaveSexton.Labs.SilverlightLabHost"
						 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
						 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
						 xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
						 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
						 xmlns:windows="clr-namespace:System.Windows;assembly=System.Windows"
						 xmlns:toolkit="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Toolkit"
						 xmlns:toolkit2="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Input.Toolkit"
						 xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"
						 xmlns:local="clr-namespace:DaveSexton.Labs"
						 DataContext="{Binding RelativeSource={RelativeSource Self}}"
						 mc:Ignorable="d"
						 d:DesignWidth="800" d:DesignHeight="600">
	<UserControl.Resources>

		<local:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
		<local:BooleanToVisibilityConverter x:Key="InverseBooleanToVisibilityConverter" TrueValue="Collapsed" FalseValue="Visible" />

		<DataTemplate x:Key="LabTemplate">
			<TextBlock>
				<Run Text="{Binding OrganizedName}" />
			</TextBlock>
		</DataTemplate>

		<Style TargetType="ComboBoxItem" BasedOn="{x:Null}" />

		<Style x:Key="Output" TargetType="RichTextBox">
			<Setter Property="FontFamily" Value="Courier New" />
			<Setter Property="AcceptsReturn" Value="True" />
			<Setter Property="IsReadOnly" Value="True" />
		</Style>

		<Style x:Key="Source" TargetType="TextBox">
			<Setter Property="FontFamily" Value="Courier New" />
			<Setter Property="AcceptsReturn" Value="True" />
			<Setter Property="IsReadOnly" Value="True" />
		</Style>

	</UserControl.Resources>

	<toolkit:DockPanel>

		<toolkit:DockPanel toolkit:DockPanel.Dock="Top" Margin="10 10 10 5">

			<TextBlock VerticalAlignment="Center" Padding="0 0 10 0">
				Current lab:
			</TextBlock>

			<ComboBox Name="LabList" Style="{x:Null}"
								IsEnabled="{Binding CanChangeLab}"
								ItemsSource="{Binding Labs}" ItemTemplate="{StaticResource LabTemplate}" />

		</toolkit:DockPanel>

		<Grid Margin="0 5 0 0">
			<Grid.ColumnDefinitions>
				<ColumnDefinition Width="*" MinWidth="25" />
				<ColumnDefinition Width="Auto" />
				<ColumnDefinition Width="*" MinWidth="25" />
			</Grid.ColumnDefinitions>
			<Grid.RowDefinitions>
				<RowDefinition Height=".75*" MinHeight="25" />
				<RowDefinition Height="Auto" />
				<RowDefinition Height="*" MinHeight="25" />
			</Grid.RowDefinitions>

			<Border Grid.Row="0" Grid.ColumnSpan="3"
							BorderBrush="{Binding ContentBorderBrush}" BorderThickness="1" >

				<ContentControl Content="{Binding SelectedItem.ActualLab, ElementName=LabList}"
												VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch" />

			</Border>

			<controls:GridSplitter Grid.Row="1" Grid.ColumnSpan="3" Height="9"
														 HorizontalAlignment="Stretch" VerticalAlignment="Center" />

			<RichTextBox Name="Output" Grid.Row="2" Grid.Column="0" Style="{StaticResource Output}" 
									 VerticalScrollBarVisibility="Auto">
				<toolkit2:ContextMenuService.ContextMenu>
					<toolkit2:ContextMenu>
						<toolkit2:MenuItem Header="Copy Selection" Click="CopyOutput">
							<toolkit2:MenuItem.Icon>
								<Image Source="Images/Copy16x16.png" />
							</toolkit2:MenuItem.Icon>
						</toolkit2:MenuItem>
						<toolkit2:MenuItem Header="Select All" Click="SelectAllOutput" />
						<toolkit2:Separator />
						<toolkit2:MenuItem Header="Clear All" Click="ClearAllOutput">
							<toolkit2:MenuItem.Icon>
								<Image Source="Images/ClearAll16x16.png" />
							</toolkit2:MenuItem.Icon>
						</toolkit2:MenuItem>
					</toolkit2:ContextMenu>
				</toolkit2:ContextMenuService.ContextMenu>
			</RichTextBox>

			<controls:GridSplitter Grid.Row="2" Grid.Column="1" Width="9"
														 VerticalAlignment="Stretch" HorizontalAlignment="Center" 
														 Visibility="{Binding HasSourceCode, Converter={StaticResource BooleanToVisibilityConverter}}" />

			<controls:TabControl Grid.Row="2" Grid.Column="2" TabStripPlacement="Bottom" BorderThickness="2"
													 Visibility="{Binding HasSourceXaml, Converter={StaticResource BooleanToVisibilityConverter}}">

				<controls:TabItem Header="XAML" Visibility="{Binding HasSourceXaml, Converter={StaticResource BooleanToVisibilityConverter}}">

					<TextBox Name="SourceXamlTextBox"
									 Text="{Binding SourceXaml}" Style="{StaticResource Source}"
									 HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
						<toolkit2:ContextMenuService.ContextMenu>
							<toolkit2:ContextMenu>
								<toolkit2:MenuItem Header="Copy Selection" Click="CopySourceXaml">
									<toolkit2:MenuItem.Icon>
										<Image Source="Images/Copy16x16.png" />
									</toolkit2:MenuItem.Icon>
								</toolkit2:MenuItem>
								<toolkit2:MenuItem Header="Select All" Click="SelectAllSourceXaml" />
							</toolkit2:ContextMenu>
						</toolkit2:ContextMenuService.ContextMenu>
					</TextBox>

				</controls:TabItem>

				<controls:TabItem Header="Code" Visibility="{Binding HasSourceCode, Converter={StaticResource BooleanToVisibilityConverter}}">

					<TextBox Name="SourceCodeTextBox"
									 Text="{Binding SourceCode}" Style="{StaticResource Source}"
									 HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
						<toolkit2:ContextMenuService.ContextMenu>
							<toolkit2:ContextMenu>
								<toolkit2:MenuItem Header="Copy Selection" Click="CopySourceCode">
									<toolkit2:MenuItem.Icon>
										<Image Source="Images/Copy16x16.png" />
									</toolkit2:MenuItem.Icon>
								</toolkit2:MenuItem>
								<toolkit2:MenuItem Header="Select All" Click="SelectAllSourceCode" />
							</toolkit2:ContextMenu>
						</toolkit2:ContextMenuService.ContextMenu>
					</TextBox>

				</controls:TabItem>

			</controls:TabControl>

			<TextBox Grid.Row="2" Grid.Column="2"
							 Name="IsolatedSourceCodeTextBox"
							 Visibility="{Binding HasSourceXaml, Converter={StaticResource InverseBooleanToVisibilityConverter}}"
							 Text="{Binding SourceCode}" Style="{StaticResource Source}"
							 HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
				<toolkit2:ContextMenuService.ContextMenu>
					<toolkit2:ContextMenu>
						<toolkit2:MenuItem Header="Copy Selection" Click="CopyIsolatedSourceCode">
							<toolkit2:MenuItem.Icon>
								<Image Source="Images/Copy16x16.png" />
							</toolkit2:MenuItem.Icon>
						</toolkit2:MenuItem>
						<toolkit2:MenuItem Header="Select All" Click="SelectAllIsolatedSourceCode" />
					</toolkit2:ContextMenu>
				</toolkit2:ContextMenuService.ContextMenu>
			</TextBox>

		</Grid>

	</toolkit:DockPanel>

</UserControl>